package cn.jinjimi.app.main.widget.biz;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import cn.jinjimi.framework.helper.annotation.EventTrace;
import cn.jinjimi.app.R;
import cn.jinjimi.app.bean.EventDataField;
import cn.jinjimi.app.bean.EventID;
import cn.jinjimi.app.managers.NoticeManager;
import cn.jinjimi.app.main.activity.SettingActivity;

/**
 * Created by Roy
 * Date: 16/12/14
 */

public class InfoFootView extends LinearLayout implements View.OnClickListener {

    /* 微站红点 */
    private ImageView ivSiteIcon;
    /* 收藏红点 */
    private ImageView ivFavIcon;
    /* 设置的红点 */
    private ImageView ivNewIcon;

    public InfoFootView(Context context) {
        super(context);
        LayoutInflater.from(getContext()).inflate(R.layout.fragment_info_foot_view, this);
        initView();
        initListener();
    }

    private void initView() {
        //初始化固定菜单所有红点
        ivSiteIcon = (ImageView) findViewById(R.id.iv_me_site_new);
        ivFavIcon = (ImageView) findViewById(R.id.iv_me_fav_new);
        ivNewIcon = (ImageView) findViewById(R.id.iv_me_setting_new);

    }

    private void initListener() {
        findViewById(R.id.rl_site).setOnClickListener(this);
        findViewById(R.id.rl_fav).setOnClickListener(this);
        findViewById(R.id.rl_setting).setOnClickListener(this);
    }

    public void dealMenuNotice() {
        ivSiteIcon.setVisibility(NoticeManager.getInstance().hasNewFeature(getContext().getString(R.string.me_mysite_title)) ? View.VISIBLE : View.INVISIBLE);
        ivFavIcon.setVisibility(NoticeManager.getInstance().hasNewFeature(getContext().getString(R.string.me_collect_title)) ? View.VISIBLE : View.INVISIBLE);
    }

    public void dealNewVersionNotice(int count) {
        ivNewIcon.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_site:
                if (ivSiteIcon.isShown()) {
                    ivSiteIcon.setVisibility(View.INVISIBLE);
                    NoticeManager.getInstance().readNewFeature(getContext().getString(R.string.me_mysite_title));
                }

                break;
            case R.id.rl_fav:  // 收藏
                openCollect();

                if (ivFavIcon.isShown()) {
                    ivFavIcon.setVisibility(View.INVISIBLE);

                    NoticeManager.getInstance().readNewFeature(getContext().getString(R.string.me_collect_title));
                }

                break;
            case R.id.rl_setting:   // 设置
                openSetting();
                break;
        }
    }

    /* 我的收藏 */
    @EventTrace(value = EventID.APP_OWNER_LIST, paramsK = {EventDataField.ParamId}, paramsV = {"收藏"})
    public void openCollect() {

    }

    /* 打开设置 */
    @EventTrace(EventID.APP_OWNER_SET)
    public void openSetting() {
        getContext().startActivity(new Intent(getContext(), SettingActivity.class));
    }

}
